package com.example.demo.hcontroller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.pojo.Houser;
import com.example.demo.service.IHouserService;

@Controller
@RequestMapping(value = "/hHouser")
public class HHouserController {

    @Autowired
    private IHouserService HouserService;

    @RequestMapping("/toHouser")
    private String toHouser(Model model, Houser Houser){
        List<Houser> list=HouserService.selectHouser();
        model.addAttribute("houserlist", list);
        return "houser";
    }

    @RequestMapping("/toupdateHouser")
    private String toupdateHouser(Model model, Houser Houser, Integer id){
        List<Houser> list=HouserService.selectHouser();
        model.addAttribute("houser", HouserService.selectByPrimaryKey(id));
        return "updatehouser";
    }

    @RequestMapping("/updateHouser")
    private String updateHouser(Model model, Houser Houser, Integer id, String name, String pwd, String tel, String sex, Integer age, String community, String email, String healthy, String preference){
        Houser.setAge(age);
        Houser.setId(id);
        Houser.setName(name);
        Houser.setPwd(pwd);
        Houser.setTel(tel);
        Houser.setSex(sex);
        Houser.setEmail(email);
        Houser.setHealthy(healthy);
        Houser.setPreference(preference);
        HouserService.updateByPrimaryKeySelective(Houser);
        return "redirect:toHouser";
    }
    

    
    @RequestMapping("/deleteHouser")
    private String deleteHouser(Model model, Houser Houser,Integer id){
    	HouserService.deleteByPrimaryKey(id);
        return "redirect:toHouser";
    }

}
